package com.atguigu07.object.equals.ex1;

import java.util.Objects;

public class Order {
    private int orderId;
    private String orderName;

    public Order(int orderId, String orderName) {
        this.orderId = orderId;
        this.orderName = orderName;
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }

    public String getOrderName() {
        return orderName;
    }

    public void setOrderName(String orderName) {
        this.orderName = orderName;
    }

    @Override
    public boolean equals(Object o) {
        if(o==this){
            return true;
        }
        if(o instanceof Order){//因为传进来的时候向上转型声明类型变为Object类了,所以需要再转一次
            //因为传进来的时候向上转型声明类型变为Object类了
            //多态性  引用形式是Object 得强转成引用形式是Order的 才能调用引用形式的方法 否则调用的是父类Object的方法
            Order o1=(Order)o;
            if(o1.orderId==this.orderId&&o1.orderName.equals(this.orderName)){
                return true;
            }
        }
        return false;
    }


}
